-
-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add more db info on span data #3231
feat: add more db info on span data #3231
Conversation
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
- add more db info on span data ([#3231](https://github.com/getsentry/sentry-cocoa/pull/3231)) If none of the above apply, you can opt out of this check by adding |
NSMutableArray<NSString *> *systems = [NSMutableArray<NSString *> array]; | ||
NSMutableArray<NSString *> *names = [NSMutableArray<NSString *> array]; | ||
[context.persistentStoreCoordinator.persistentStores enumerateObjectsUsingBlock:^( | ||
__kindof NSPersistentStore *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) { | ||
[systems addObject:obj.type]; | ||
if (obj.URL != nil) { | ||
[names addObject:obj.URL.path]; | ||
} else { | ||
[names addObject:@"(null)"]; | ||
} | ||
}]; | ||
[span setDataValue:[systems componentsJoinedByString:@";"] forKey:@"db.system"]; | ||
[span setDataValue:[names componentsJoinedByString:@";"] forKey:@"db.name"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new db.name
and db.system
data.
__block id<SentrySpan> fetchSpan = nil; | ||
__block id<SentrySpan> saveSpan = nil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed this variable
if (fetchSpan) { | ||
[SentryLog | ||
logWithMessage:[NSString | ||
stringWithFormat:@"SentryCoreDataTracker automatically " | ||
@"started a new span with description: %@, " | ||
@"operation: %@", | ||
fetchSpan.description, SENTRY_COREDATA_FETCH_OPERATION] | ||
andLevel:kSentryLevelDebug]; | ||
|
||
[fetchSpan setDataValue:operations forKey:@"operations"]; | ||
} | ||
saveSpan = [span startChildWithOperation:SENTRY_COREDATA_SAVE_OPERATION | ||
description:[self descriptionForOperations:operations | ||
inContext:context]]; | ||
saveSpan.origin = SentryTraceOriginAutoDBCoreData; | ||
}]; | ||
|
||
if (saveSpan) { | ||
SENTRY_LOG_DEBUG(@"SentryCoreDataTracker automatically started a new span with " | ||
@"description: %@, operation: %@", | ||
saveSpan.description, saveSpan.operation); | ||
|
||
[saveSpan setDataValue:operations forKey:@"operations"]; | ||
} else { | ||
SENTRY_LOG_ERROR(@"managedObjectContext:save:originalImp: saveSpan is nil"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this out of the useSpan:
scope, like the code for fetch operations.
stringWithFormat:@"SentryCoreDataTracker automatically " | ||
@"started a new span with description: %@, " | ||
@"operation: %@", | ||
fetchSpan.description, SENTRY_COREDATA_FETCH_OPERATION] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should've been SENTRY_COREDATA_SAVE_OPERATION, but I did one better and just access SentrySpan.operation for both such logs (here and in fetches)
- (void)mainThreadExtraInfo:(SentrySpan *)span | ||
- (void)addExtraInfoToSpan:(SentrySpan *)span withContext:(NSManagedObjectContext *)context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed this method as it's doing more than just main thread stuff now.
[SentryLog | ||
logWithMessage:[NSString stringWithFormat: | ||
@"SentryCoreDataTracker automatically " | ||
@"started a new span with description: %@, operation: %@", | ||
fetchSpan.description, SENTRY_COREDATA_FETCH_OPERATION] | ||
andLevel:kSentryLevelDebug]; | ||
SENTRY_LOG_DEBUG(@"SentryCoreDataTracker automatically started a new span with " | ||
@"description: %@, operation: %@", | ||
fetchSpan.description, fetchSpan.operation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converted all the logs to the new macros. Also here's the second place I changed interpolating the operation constant for SentrySpan.operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this 👍
Performance metrics 🚀
|
Revision | Plain | With Sentry | Diff |
---|---|---|---|
c2ec420 | 1256.27 ms | 1269.24 ms | 12.97 ms |
e24290f | 1239.94 ms | 1248.28 ms | 8.34 ms |
28333b6 | 1186.29 ms | 1225.18 ms | 38.89 ms |
a176fc4 | 1239.78 ms | 1258.98 ms | 19.20 ms |
794f87f | 1225.78 ms | 1243.46 ms | 17.68 ms |
3cba0e8 | 1250.86 ms | 1258.39 ms | 7.53 ms |
7cd187e | 1196.51 ms | 1226.04 ms | 29.53 ms |
9e96fd6 | 1207.20 ms | 1229.40 ms | 22.20 ms |
0776564 | 1224.35 ms | 1247.26 ms | 22.91 ms |
25e65a5 | 1249.08 ms | 1277.78 ms | 28.70 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
c2ec420 | 20.76 KiB | 401.65 KiB | 380.89 KiB |
e24290f | 22.84 KiB | 403.51 KiB | 380.66 KiB |
28333b6 | 20.76 KiB | 424.69 KiB | 403.93 KiB |
a176fc4 | 22.84 KiB | 403.24 KiB | 380.39 KiB |
794f87f | 20.76 KiB | 401.37 KiB | 380.61 KiB |
3cba0e8 | 22.84 KiB | 403.19 KiB | 380.34 KiB |
7cd187e | 20.76 KiB | 401.66 KiB | 380.90 KiB |
9e96fd6 | 20.76 KiB | 425.80 KiB | 405.04 KiB |
0776564 | 20.76 KiB | 399.19 KiB | 378.43 KiB |
25e65a5 | 22.85 KiB | 403.19 KiB | 380.34 KiB |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3231 +/- ##
=============================================
+ Coverage 89.153% 89.209% +0.055%
=============================================
Files 502 502
Lines 54213 54225 +12
Branches 19457 19469 +12
=============================================
+ Hits 48333 48374 +41
+ Misses 5014 4990 -24
+ Partials 866 861 -5
... and 11 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
XCTAssertEqual(try XCTUnwrap(dbSpan.data["db.system"] as? String), "SQLite") | ||
XCTAssert(try XCTUnwrap(dbSpan.data["db.name"] as? NSString).contains(TestCoreDataStack.databaseFilename)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertions for the new properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l
: maybe re-add the assert for origin
and read_count
(for read operations)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, i removed those by accident
override var hasChanges: Bool { | ||
return ((inserted?.count ?? 0) > 0) || | ||
((deleted?.count ?? 0) > 0) || | ||
((updated?.count ?? 0) > 0) || super.hasChanges |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to add || super.hasChanges
for SentryCoreDataTrackerTests.test_Save() to work again, because it doesn't rely on the subclass properties.
if (obj.URL != nil) { | ||
[names addObject:obj.URL.path]; | ||
} else { | ||
[names addObject:@"(null)"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
h: I believe we need a better option to fallback. This is not user friendly and I'm foreseeing complains.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to any alternatives. Nobody has proposed any so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also be interested to know the cases where the URL is nil. I expected it to be nil for in memory stores, but even that has a value like memory://563428497
. It is probably nil if there is no persistent store/coordinator at all, but then I don't know what the complaint would be. In that case I question if we should even be reporting anything at all, but that kind of refactor is out of scope for this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to any alternatives.
<App Name>:coredata
anything really other than (null)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already gather the equivalent of that in the type
.
In this case, we should send some kind of sentinel value so the frontend knows to render a special state equivalent to "there was no database". This seems as good as any.
If I were a customer I would rather know that this value was not available, vs having it covered up by a default value like what you're proposing. It could help find an upstream error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @armcknight here - in case this occurs a lot and provides not enough context we can always re-iterate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the opportunistic refactoring as well 💯
[SentryLog | ||
logWithMessage:[NSString stringWithFormat: | ||
@"SentryCoreDataTracker automatically " | ||
@"started a new span with description: %@, operation: %@", | ||
fetchSpan.description, SENTRY_COREDATA_FETCH_OPERATION] | ||
andLevel:kSentryLevelDebug]; | ||
SENTRY_LOG_DEBUG(@"SentryCoreDataTracker automatically started a new span with " | ||
@"description: %@, operation: %@", | ||
fetchSpan.description, fetchSpan.operation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this 👍
XCTAssertEqual(try XCTUnwrap(dbSpan.data["db.system"] as? String), "SQLite") | ||
XCTAssert(try XCTUnwrap(dbSpan.data["db.name"] as? NSString).contains(TestCoreDataStack.databaseFilename)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l
: maybe re-add the assert for origin
and read_count
(for read operations)
e902924
to
9fd258d
Compare
📜 Description
Add the persistent store types and URLs to the span data for Core Data tracking.
Also a couple refactors:
SentryCoreDataTrackerTests.TestNSManagedContext
toTestCoreDataStack.managedObjectContext
💡 Motivation and Context
#3212